<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分析快速排序</title>
</head>

<body>
    <script>
        function quickSort(arr, l, r) {
            if (l >= r) {
                return
            }
            let i = l
            let j = r
            let pivot = arr[i]
            while (i < j) {
                while (i < j && arr[j] > pivot) {
                    j--
                }
                while (i < j && arr[i] <= pivot) {
                    i++
                }
                let temp = arr[i]
                arr[i] = arr[j]
                arr[j] = temp
            }
            let temp = arr[i]
            arr[i] = arr[l]
            arr[l] = temp
            quickSort(arr, l, i - 1)
            quickSort(arr, i + 1, r)
        }
        let arr = [4,7,5,2,9]
        console.log(quickSort(arr, 0, arr.length - 1))
        console.log(arr)
    </script>
</body>

</html>